<script type="text/javascript" src="<?=base_url().'resource/js/layer/layer.js'?>" charset="utf-8"></script>
<script type="text/javascript">
    //弹出用户修改框
    function editWarehouse(id,add)
    {
        var title='';
        title="添加新仓库";
        layer.open({
            type: 1,
            title: title,
            area: ['540px', '400px'], //宽高
            content: $('#warehouseDiv')
        });
        $('#warehouseForm').attr('action',"<?=blang_url('wms/AuxFunction/addWarehouse/')?>");
        $('#whs_code').val('');
        $('#whs_name').val('');
        $('#platform_num').val('');
        $('#remark').val('');
    }

    function addSendVerify()
    {
        if($('#whs_code').val()=='')
        {
            alert('仓库代码不能为空！');
            return false;
        }
        if($('#whs_name').val()=='')
        {
            alert('仓库名称不能为空！');
            return false;
        }
        return true;
    }
</script>
<style type="text/css">
    select
    {
        width: 180px;
        height: 20px;
    }
</style>
<!--top结束-->
<div class="mian">
    <div class="mian1">
        <div class="mian2">
            <!--left start-->
            <?php $this->load->view('defaults/common/left'); ?>
            <!--left end-->
            <!--right start-->
            <div class="right">
                <!--breadcrumb start-->
                <div class="righta"><?= $this->breadcrumb->generateHTML(); ?> </div>
                <!--breadcrumb end-->

                <!-- contents start -->
                <div id="contents">
                    <div id="ct_search">
                        <form action="<?=blang_url('wms/'.$class.'/'.$func.'/')?>" method="post" name="searchform"  >
                            <table id="search_tb">
                                <tr>
                                    <label>仓库代码：
                                        <select name="whs_code">
                                            <option value="">All</option>
                                            <?php foreach ($whsCodeList as $val):?>
                                               <option value="<?=$val['whs_code']?>" <?=(isset($whs_code) and $whs_code==$val['whs_code'])?'selected="selected"':'';?> ><?=$val['whs_name']?></option>
                                            <?php endforeach?>
                                        </select>&nbsp;
                                    </label>
                                    <label>仓库类型：
                                    <select name="whs_type">
                                            <option value="">All</option>
                                            <?php foreach ($whsTypeList as $key => $val):?>
                                               <option value="<?=$key?>" <?=(isset($whs_type) and $whs_type==$key)?'selected="selected"':'';?> ><?=$val?></option>
                                            <?php endforeach?>
                                        </select>&nbsp;</label>
                                        <input type="submit" name="searchSubmit" value="<?=lang('public_cx')?> " />
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </div>
                    <div class="ct_content">
                        <table class="tbwd800">
                            <tr>
                                <th width="6%">序号</th>
                                <th width="10%">仓库代码</th>
                                <th width="20%">仓库名称</th>
                                <th width="10%">仓库类型</th>
                                <th width="10%">状态</th>
                                <th width="15%">备注</th>
                            </tr>
                            <?php foreach ($dataList as $key => $row):?>
                                <tr>
                                    <td align="center"><?=$key + 1?></td>
                                    <td><?=$row['whs_code']?></td>
                                    <td><?=$row['whs_name']?></td>
                                    <td><?=($row['whs_type']=='merchant')?'代管仓':'维保仓';?></td>
                                    <td align='center'>
                                        <?php if(!empty($row['active'])):?>
                                            <a href="<?=blang_url('wms/AuxFunction/setActive/'.$row['whs_code'].'/0')?>">启用</a>
                                        <?php else:?>
                                            <a href="<?=blang_url('wms/AuxFunction/setActive/'.$row['whs_code'].'/1')?>">关闭</a>
                                        <?php endif?>
                                    </td>
                                    <td><?=$row['remark']?></td>
                                </tr>
                            <?php endforeach?>
                            <?php if(isset($pageShow) and !empty($pageShow)):?>
                                <tr align="center">
                                    <td colspan="6"><?=$pageShow?></td>
                                </tr>
                            <?php endif?>
                            <tr>
                                <th colspan="6" height="40"><button onclick="editWarehouse('',1)">添加仓库</button></th>
                            </tr>
                        </table>
                    </div>
                </div>
                <!-- contents end -->
            </div>
            <!--right end-->
            <div class="clear"></div>
        </div>
    </div>
</div>

<div class="ct_content" style="display: none;margin-left: 20px;margin-top: 10px;" id="warehouseDiv">
    <form action="" method="post" id="warehouseForm">
        <table cellspacing="0" style="border-collapse: collapse;width: 500px;">
            <tr>
                <th>站点：</th>
                <td>
                    <select name="point" id="point" onchange='genWshCode()'>
                        <?php foreach ($pointList as $val):?>
                            <option value="<?=$val['point']?>"><?=$val['point']?></option>
                        <?php endforeach;?>
                    </select>
                </td>
            </tr>
            <tr>
                <th>SAP仓库代码：</th>
                <td>
                    <select name="sap_whs_code" id="sap_whs_code" onchange='genWshCode()'>
                        <?php foreach ($sapWhsCode as $key => $val):?>
                            <option value="<?=$key?>"><?=$key?></option>
                        <?php endforeach;?>
                    </select>
                </td>
            </tr>
            <tr>
                <th>仓库类型：</th>
                <td>
                    <select name="whs_type" id="whs_type" onchange='genWshCode()'>
                        <?php foreach ($whsTypeList as $key => $val):?>
                            <option value="<?=$key?>"><?=$val?></option>
                        <?php endforeach;?>
                    </select>
                </td>
            </tr>
            <tr>
                <th>品牌名称：</th>
                <td>
                    <select name="platform_num" id="platform_num" onchange='genWshCode()'>
                        <option value="">无</option>
                        <?php foreach ($platformNumList as $key => $val):?>
                            <option value="<?=$key?>"><?=$val?></option>
                        <?php endforeach;?>
                    </select> <span  style='color: red' class='msg'></span>
                </td>
            </tr>
            <tr>
                <th>仓库代码：</th>
                <td><input type="text" id="whs_code" name="whs_code" size="50" readonly style="border:none"></td>
            </tr> 
            <tr>
                <th>仓库名称：</th>
                <td><input type="text" id="whs_name" name="whs_name" size="50" readonly style="border:none"></td>
            </tr>
            <tr>
                <th>备注：</th>
                <td><textarea name='remark' id='remark' style="width: 280px;height:65px;"></textarea></td>
            </tr>
            <tr align="center">
                <td colspan="2">
                    <input type="submit" onclick="return addSendVerify()" value="<?=lang('public_tj')?>">
                </td>
            </tr>
        </table>
    </form>
</div>
<div style="clear:both"></div>
<script type="text/javascript">
    function genWshCode()
    {
        var sap_whs_code_json = {'W001':'T01','W005':'T03','W006':'T02','W014':'T01','W033':'T05','W032':'T06','W049':'T07'};
        var sap_whs_name_json = {'W001-T01':'DHHT美国仓的T06美国维保 虚拟仓','W005-T03':'DHHT西班牙仓 T03西班牙维保  虚拟仓','W006-T02':'DHHT俄罗斯仓T02俄罗斯维保 虚拟仓','W014-T01':'DHHT德国仓T01德国维保  虚拟仓','W033-T05':'DHHT英国仓的T05英国维保 虚拟仓','W032-T06':'DHHT美国仓的T06美国维保 虚拟仓','W049-T07':'DHHT法国仓T07法国维保'};
        var sap_whs_code = $('#sap_whs_code').val();
        var whs_type = $('#whs_type').val();
        var platform_num = $('#platform_num').val();
        var point = $('#point').val();
        var whs_code;
        var whs_name;
        $('#whs_code').val('');
        $('#whs_name').val('');
        if(whs_type == 'merchant')
        {
            $('#platform_num').removeAttr('disabled');
            if(platform_num!='')
            {
                //代管仓
                $('.msg').html('');
                whs_code = sap_whs_code+'-'+platform_num;
                whs_name = $("#platform_num").find("option:selected").text()+'-'+point;
            }else
            {
                $('.msg').html('不能为空');
                return;
            }
        }else
        {
            $('#platform_num').val('');
            $('#platform_num').attr('disabled',true);
            $('.msg').html('');
            whs_code = sap_whs_code+'-'+sap_whs_code_json[sap_whs_code];
            whs_name = sap_whs_name_json[whs_code];
        }
        $('#whs_code').val(whs_code);
        $('#whs_name').val(whs_name);
    }
</script>